home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillip2 / invert.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  2KB  |  90 lines

  1.  
  2.    /***********************************************
  3.    *
  4.    *   file d:\cips\invert.c
  5.    *
  6.    *   Functions: This file contains
  7.    *      main
  8.    *
  9.    *   Purpose:
  10.    *      This program takes an image file and
  11.    *      inverts it. It works with 8 bit images
  12.    *      only.
  13.    *
  14.    *   External Calls:
  15.    *      tiff.c - read_tiff_header
  16.    *      rtiff.c - read_tiff_image
  17.    *      wtiff.c - create_allocate_tiff_file
  18.    *                write_array_into_tiff_image
  19.    *
  20.    *   Modifications:
  21.    *      6 March 1993 - created
  22.    *
  23.    ***********************************************/
  24.  
  25. #include "cips.h"
  26.  
  27.  
  28.  
  29. short the_image[ROWS][COLS];
  30. short out_image[ROWS][COLS];
  31.  
  32. main(argc, argv)
  33.    int argc;
  34.    char *argv[];
  35. {
  36.    char     r[80], name1[80], name2[80];
  37.    int      a, b, count, i, ie, il, j,
  38.             le, length, ll,  width;
  39.    struct   tiff_header_struct image_header;
  40.  
  41.  
  42.    my_clear_text_screen();
  43.  
  44.    if(argc != 3){
  45.       printf("\nusage: invert in-file out-file\n");
  46.       exit(1);
  47.    }
  48.  
  49.    strcpy(name1, argv[1]);
  50.    strcpy(name2, argv[2]);
  51.  
  52.    il     = 1;
  53.    ie     = 1;
  54.    ll     = ROWS+1;
  55.    le     = COLS+1;
  56.  
  57.    read_tiff_header(name1, &image_header);
  58.    round_off_image_size(&image_header,
  59.                         &length, &width);
  60.    image_header.image_length = length*ROWS;
  61.    image_header.image_width  = width*COLS;
  62.    create_allocate_tiff_file(name2, &image_header,
  63.                              out_image);
  64.  
  65.    count = 1;
  66.  
  67.    for(i=0; i<length; i++){
  68.       for(j=0; j<width; j++){
  69.          printf("\nRunning %d of %d", 
  70.                 count, length*width);
  71.          count++;
  72.          read_tiff_image(name1, the_image,
  73.                          il + i*ROWS,
  74.                          ie + j*COLS,
  75.                          ll + i*ROWS,
  76.                          le + j*COLS);
  77.  
  78.          for(a=0; a<ROWS; a++)
  79.             for(b=0; b<COLS; b++)
  80.                out_image[a][b] = 255-the_image[a][b];
  81.  
  82.          write_array_into_tiff_image(name2, out_image,
  83.                                      il + i*ROWS,
  84.                                      ie + j*COLS,
  85.                                      ll + i*ROWS,
  86.                                      le + j*COLS);
  87.       }  /* ends loop over i */
  88.    }  /* ends loop over j */
  89. }  /* ends main */
  90.